cap log close

global path = "****"

local name= "income_het_gen"
local date = "060420"
global logname = "$path/`name'_`date'.log"

clear
set more off
set matsize 11000
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample_prepcode.dta", clear

replace age_2017=0 if age_2017<0

replace age_2017=0 if age_2017<0
rename fpl_frac magi_fpl2015

gen cov2016_11 = (covered2016 - any_dec == 11)
gen age_45_64 = age_2017 < 65 & age_2017 >= 45
gen self_prepared = (prep_tin_flag == "")
gen no_botched_rollout = inlist(state,"CA","CO","CT","DC","KY","MN","NY","RI","WA")
gen botched_rollout = (no_botched_rollout == 0)
gen income = (magi_fpl2015<=1.38)
gen age_45 = (age_2017 >= 45)

foreach var in exchange medicaid esi off_exchange va medicare{
gen `var'1718 = `var'2017 + `var'2018
}

*Table: Effect by Income and Expansion State (Intensive Margin)

*Panel A: All Ages 

*Column 1: FPL <= 1.38
reg covered1718 treatment if notall16 == 1 & magi_fpl2015<=1.38, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_fpl_exp_`date'.ster", replace

*Column 2: FPL > 1.38
reg covered1718 treatment if notall16 == 1 & magi_fpl2015>1.38, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_fpl_exp_`date'.ster", append

*Column 3: FPL <= 1.38 & Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_fpl_exp_`date'.ster", append

*Column 4: FPL > 1.38 & Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_fpl_exp_`date'.ster", append

*Column 5: FPL <= 1.38 & Non-Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 0, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_fpl_exp_`date'.ster", append

*Column 6: FPL > 1.38 & Non-Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 0, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_fpl_exp_`date'.ster", append

*Panel B: Ages 45-64

*Column 1: FPL <= 1.38
reg covered1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & age_45_64 == 1 , cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect45_64_fpl_exp_`date'.ster", replace

*Column 2: FPL > 1.38
reg covered1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect45_64_fpl_exp_`date'.ster", append

*Column 3: FPL <= 1.38 & Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 1 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect45_64_fpl_exp_`date'.ster", append

*Column 4: FPL > 1.38 & Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 1 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect45_64_fpl_exp_`date'.ster", append

*Column 5: FPL <= 1.38 & Non-Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015<=1.38 & expansion == 0 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect45_64_fpl_exp_`date'.ster", append

*Column 6: FPL > 1.38 & Non-Expansion State
reg covered1718 treatment if notall16 == 1 & magi_fpl2015>1.38 & expansion == 0 & age_45_64 == 1, cl(tin)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)&treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect45_64_fpl_exp_`date'.ster", append
	


log close

